package com.atguigu.stgy.admin.controller;

import com.atguigu.stgy.admin.service.AttrKeyService;
import com.atguigu.stgy.model.entity.AttrKey;
import com.atguigu.stgy.admin.service.impl.AttrKeyServiceImpl;
import com.atguigu.stgy.model.result.R;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 房间基本属性表(attr_key)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/admin/attr")
public class AttrKeyController {
    /**
     * 服务对象
     */
    @Resource
    private AttrKeyService attrKeyService;
    @Operation(summary = "查询房间基本信息属性和值列表")
    @GetMapping("list")
    public R<List<AttrKey>> list(){
        List<AttrKey> attrs = attrKeyService.listAttrAndVals();
        return R.ok(attrs);
    }
    ///admin/attr/key/saveOrUpdate
    @Operation(summary = "新增/更新 房间基本信息属性")
    @PostMapping("key/saveOrUpdate")
    public R<List<AttrKey>> saveOrUpdate(@RequestBody AttrKey attrKey){
        attrKeyService.saveOrUpdate(attrKey);
        return R.ok();
    }
    ///attr/key/deleteById?attrKeyId=1795621399293964289
    @Operation(summary = "删除 房间基本信息属性")
    @DeleteMapping("key/deleteById")
    public R deleteById(@RequestParam("attrKeyId")Long attrKeyId){
        attrKeyService.removeById(attrKeyId);
        return R.ok();
    }
}
